<?php

namespace app\home\model;
use think\Db;
use think\Model;

class MemberModel extends Model
{
    //查询会员信息
    public function MemberData(){
        $userguid = cmf_get_current_user();//获取用户的guid $user["m_guid"]
        $result = Db::name("member")->where("m_guid",$userguid["m_guid"])->alias("a")
                ->join('__MEMBERLEVEL__ b','b.ml_guid=a.m_guid','left')
                ->field('a.*,b.name')
                ->find();
        return $result;
    }
    //提交会员更改的信息
    public function MemberEdit($data){
        $log = array();
        $log['nick_name'] = $data['nick_name'];
        $log['address'] = $data['address'];
        $userguid = cmf_get_current_user();//获取用户的guid $user["m_guid"]
        $result = Db::name("member")->where("m_guid",$userguid["m_guid"])->update($log);
        return $result;
    }
    //修改会员密码提交数据
    public function MemberPassword($data){
        $log = array();
        $log['pass_word'] = $data['pass_word'];
        $log['pay_word'] = $data['pay_word'];
        $userguid = cmf_get_current_user();//获取用户的guid $user["m_guid"]
        $result = Db::name("member")->where("m_guid",$userguid["m_guid"])->update($log);
        return $result;
    }
    //查询会员历史订单记录
    public function MemberOrderOld(){
         $userguid = cmf_get_current_user();//获取用户的guid $user["m_guid"]
         $result = Db::name("order")->where("member_id",$userguid["m_guid"])->alias("a")
                 ->join('__SHOP__ b','b.re_guid=a.shop_id','left')
                 ->join('__COUPON__ c','c.cou_guid=a.apporder_guid','left')
                 ->field('a.*,b.shop_name,c.voucher_code,c.coucher_money')->order("a.c_time DESC")
                 ->paginate(10);
         return $result;
    }
    //在订单页面查询会员预约详情
    public function MemberApption($or_guid){
        $result = Db::name("order")->where("or_guid",$or_guid)->alias("a")
                ->join('__APPOINTMENTORDER__ b','b.ap_guid=a.apporder_guid','left')
                ->join('__GOODS__ c','c.goods_guid=b.product_id','left')
                ->field('a.*,c.goods_name,b.app_time,b.appone_time,b.end_time,b.money,b.status,b.for_status')->order("b.app_time DESC")
                ->paginate(10);
        return $result;
    }
    //会员查询个人所有的预约记录
    public function MemberAppListo($user){
        $result = Db::name("appointmentorder")->where("member_guid",$user["m_guid"])->alias("a")
                ->join('__GOODS__ b','b.goods_guid=a.product_id','left')
                ->field('a.*,b.goods_name')
                ->order("a.app_time DESC")->paginate(10);
        return $result;
    }
    //会员卡查询
    public function MemberCardXun($user){
        $card_id = Db::name("membercard")->where("member_id",$user["m_guid"])->find();//查询会员卡id  $card_id["card_id"]
        $result = Db::name("mcard")->where("cd_guid",'in',$card_id["card_id"])
                 ->order("c_time DESC")->paginate(10);
        return $result;
    }
}

